<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            font-size: 16px;
            list-style: none;
        }

        .login {
            width: 400px;
            height: 400px;
            border: 2px solid #000;
            margin: 50px auto;
        }

        .block {
            position: relative;
            margin-top: 70px;
            margin-left: 100px;
        }

        input {
            height: 40px;
            border-radius: 10px;
        }

        p {
            position: relative;
            margin-top: 10px;
            color: aqua;
            cursor: pointer;
            margin-left: 240px;
        }
        .login .block input{
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 200px;
            outline: none;
            box-sizing: border-box;
            /* text-align: center; */
            /* cursor: pointer; */
        }

        

       
    </style>
</head>

<body>
    <div class="login">
        <div class="block">
            <input type="text" placeholder="手机号/用户名/邮箱">
        </div>
        <div class="block">
            <input type="text" placeholder="密码不能为空">
        </div>
        <p>忘记密码?</p>
        <div class="block">
            <input type="button" value="登陆" >
        </div>
    </div>
</body>
</html>
<script src="2217二阶段2/day06/04-ajax.js"></script>
<script>
    var inputs = document.querySelectorAll('.login .block input')
    inputs[2].onclick = function () {
        //对表单内容做校验( 为空校验, 格式校验 )
        if (inputs[0].value && inputs[1].value) {
            //if( /^1[3-9]\d{9}$/.test( inputs[0].value ) && /^\d{4}$/.test(inputs[1].value) ){
            if (/^\d{4}$/.test(inputs[1].value)) {
                //通过校验, 发起登陆请求
                ajax('get', 'https://yantianfeng.com/api/login', {
                    username: inputs[0].value,
                    password: inputs[1].value
                }, function (data) {
                    //console.log(data);
                    if (data.status == 200) {
                        console.log('登陆成功');
                    } else {
                        console.log('登陆失败!');
                        console.log(data.status);
                    }
                })
            } else {
                alert('请输入正确的手机号/密码')
            }
        } else {
            alert('用户名/密码不能为空!')
        }
    }
</script>